import * as API from "@/api/index.js"
export function connect(){
	//------------------------------------------------初始化ID用于websokte------------------------------------------------
	console.log("被调用")
	API.GET("/v1/flash/session").then(ret=>{
		let that=this
		let socketId=ret.data.Data
		if(ret.data.IsPositive){   
			if(ret.header["liberSession"]!=undefined && ret.header["liberSession"]!=""){
				uni.setStorageSync("liber_session",ret.header["liberSession"])
			}
			
			//------------------------------------------------websoket服务------------------------------------------------
			console.log(API.baseSocket+"?clntid="+uni.getStorageSync("liber_session"),'连接地址')
			uni.connectSocket({
			    url: API.baseSocket+"?clntid="+uni.getStorageSync("liber_session"),
				complete: (res)=> {console.log("连接成功",res)}
			});
			uni.onSocketOpen(function (res) {
			  console.log('WebSocket连接已打开');
			  
			});
			uni.onSocketError(function (res) {
			  console.log('WebSocket连接打开失败，请检查！');
			});
			uni.onSocketMessage(function (res) {           //监听服务端的发送信息
			   console.log('收到服务器内容：' + res.data);
			   let resDataParse=JSON.parse(res.data)
			   if(resDataParse.code==200){
				   console.log("下单成功")
				   plus.push.createMessage(resDataParse.content, {}, {
				   				title: resDataParse.title
				   });
			   }
			});
		}
		
	})
}